﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BIS.Portal.Modules.CMS.Entity;
using BIS.Utility.DAL;
using BIS.Utility.DAL.DataMapper;

namespace BIS.Portal.Modules.CMS.DAL
{
    public class AdminCmsDisplayTypeDAL
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IList<AdminCmsDisplayTypeEntity> GetAllDisplayType()
        {
            IList<AdminCmsDisplayTypeEntity> list;

            using (IDataReader reader = SqlHelper.ExecuteReader(DALConnection.ConnectionString,
                                        CommandType.StoredProcedure,
                                        "BIS_sCMS_DISPLAY_TYPE_GetAllDisplayType"))
            {
                list = EntityMapper.FillCollection<AdminCmsDisplayTypeEntity>(reader);
            }

            return list;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="displayTypeId"></param>
        /// <returns></returns>
        public static AdminCmsDisplayTypeEntity GetByDisplayTypeId(int displayTypeId)
        {
            AdminCmsDisplayTypeEntity entity;

            using (IDataReader reader = SqlHelper.ExecuteReader(DALConnection.ConnectionString,
                                        CommandType.StoredProcedure,
                                        "BIS_sCMS_DISPLAY_TYPE_GetByDisplayTypeId",
                                        new SqlParameter("@display_type_id", displayTypeId)))
            {
                entity = EntityMapper.FillObject<AdminCmsDisplayTypeEntity>(reader);
            }

            return entity;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmsDisplayType"></param>
        /// <returns></returns>
        public static int Insert(AdminCmsDisplayTypeEntity cmsDisplayType)
        {
            SqlParameter[] param = new SqlParameter[]
                                       {
                                           new SqlParameter("@Display_type_name", cmsDisplayType.Display_type_name),
                                           new SqlParameter("@Last_update", cmsDisplayType.Last_update),
                                           new SqlParameter("@Last_update_by",cmsDisplayType.Last_update_by),
                                           new SqlParameter("@Status", cmsDisplayType.Status)
                                       };
            return SqlHelper.ExecuteNonQuery(DALConnection.ConnectionString,
                                                          CommandType.StoredProcedure,
                                                          "BIS_sCMS_DISPLAY_TYPE_Insert",
                                                          param);

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmsDisplayType"></param>
        /// <returns></returns>
        public static int Update(AdminCmsDisplayTypeEntity cmsDisplayType)
        {
            SqlParameter[] param = new SqlParameter[]
                                       {
                                           new SqlParameter("@display_type_id", cmsDisplayType.Display_type_id),
                                           new SqlParameter("@Display_type_name", cmsDisplayType.Display_type_name),
                                           new SqlParameter("@Last_update", cmsDisplayType.Last_update),
                                           new SqlParameter("@Last_update_by",cmsDisplayType.Last_update_by),
                                           new SqlParameter("@Status", cmsDisplayType.Status)
                                       };
            return SqlHelper.ExecuteNonQuery(DALConnection.ConnectionString,
                                                          CommandType.StoredProcedure,
                                                          "BIS_sCMS_DISPLAY_TYPE_Update",
                                                          param);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmsDisplayId"></param>
        /// <returns></returns>
        public static int Delete(int cmsDisplayId)
        {
            return SqlHelper.ExecuteNonQuery(DALConnection.ConnectionString,
                                             CommandType.StoredProcedure,
                                             "BIS_sCMS_DISPLAY_TYPE_Delete",
                                             new SqlParameter("@display_type_id", cmsDisplayId));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmsDisplayId"></param>
        /// <returns></returns>
        public static int GetNumOfUseOtherTable(int cmsDisplayId)
        {
            SqlParameter paraNumOfUse = new SqlParameter("@numOfUse", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };

            SqlParameter[] sqlParameters = new SqlParameter[]
                                               {
                                                   new SqlParameter("@display_type_id",cmsDisplayId),
                                                   paraNumOfUse
                                               };
            SqlHelper.ExecuteNonQuery(DALConnection.ConnectionString,
                                             CommandType.StoredProcedure,
                                             "BIS_sCMS_DISPLAY_TYPE_GetNumOfUseOtherTable",
                                            sqlParameters);

            if (paraNumOfUse.Value == null)
                return 0;
            int num = 0;
            int.TryParse(paraNumOfUse.Value.ToString(), out num);

            return num;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="displayTypeId"></param>
        /// <param name="status"></param>
        /// <param name="LastUpdate"></param>
        /// <param name="updateBy"></param>
        /// <returns></returns>
        public static int UpdateStatus(int displayTypeId, int status, DateTime LastUpdate, string updateBy)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
                                               {
                                                   new SqlParameter("@display_type_id",displayTypeId),
                                                   new SqlParameter("@last_update",LastUpdate),
                                                   new SqlParameter("@last_update_by",updateBy),
                                                   new SqlParameter("@status",status)
                                               };
            return SqlHelper.ExecuteNonQuery(DALConnection.ConnectionString,
                                              CommandType.StoredProcedure,
                                              "BIS_sCMS_DISPLAY_TYPE_UpdateStatus",
                                             sqlParameters);

        }

    }
}
